import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Restaurant } from './restaurant.entity';

export type MarkType = 'today' | 'week';

@Entity('restaurant_marks')
export class RestaurantMark {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid' })
  restaurant_id: string;

  @Column({ type: 'varchar', length: 255 })
  restaurant_name: string;

  @Column({
    type: 'enum',
    enum: ['today', 'week'],
  })
  mark_type: MarkType;

  @CreateDateColumn({ type: 'timestamp' })
  created_at: Date;

  @Column({ type: 'timestamp' })
  expires_at: Date;

  // 关联关系
  @ManyToOne(() => Restaurant, (restaurant) => restaurant.marks, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'restaurant_id' })
  restaurant: Restaurant;
}
